{% load i18n %}
{% load promgen %}
<tr>
  <td class="col-xs-3" v-pre>
    {{ user.username }}
    {% if user.username == object.owner.username %}
    <span class="label label-primary">OWNER</span>
    {% endif %}
  </td>
  <td class="col-xs-3" v-pre>{{ user.email }}</td>
  <td class="col-xs-3" style="word-break: break-all" v-pre>
    {% for perm in perms %}
    <span
      class="label
      {% if perm == 'Admin' %} label-danger
      {% elif perm == 'Editor' %} label-info
      {% else %} label-success
      {% endif %}"
    >
      {{ perm|upper }}
    </span>
    {% endfor %}

    {% if user.username != object.owner.username %}
    <button style="background:none" class="btn btn-xs" data-toggle="collapse" data-target="#user{{user.id}}">
      <span class="glyphicon glyphicon-cog" aria-hidden="true"></span>
    </button>
    <div class="collapse" id="user{{user.id}}">
      <form method="post" action="{% url 'permission-assign' %}" style="display: inline">
        {% csrf_token %}
        <input name="next" type="hidden" value="{{ request.get_full_path }}#members" />
        <input name="model" type="hidden" value="{{ object | klass }}" />
        <input name="id" type="hidden" value="{{ object.id }}" />
        <input name="username" type="hidden" value="{{ user.username }}" />
        <input name="perm-type" type="hidden" value="user" />
        {{ permission_form.permission }}
        <button class="btn btn-primary btn-xs">Change</button>
      </form>
    </div>
    {% endif %}
  </td>
  <td class="col-xs-3" v-pre>
    {% if user.username != object.owner.username %}
    <form
      method="post"
      action="{% url 'permission-delete' %}"
      onsubmit="return confirm('{% trans 'Delete all permissions for user?' %}')"
    >
      {% csrf_token %}
      <input type="hidden" name="username" value="{{ user.username }}" />
      <input name="next" type="hidden" value="{{ request.get_full_path }}#members" />
      <input name="model" type="hidden" value="{{ object | klass }}" />
      <input name="id" type="hidden" value="{{ object.id }}" />
      <input name="perm-type" type="hidden" value="user" />
      <button type="submit" class="btn btn-danger btn-xs">Delete</button>
      {% if object|klass == "Service" %}
      <div class="form-check">
        <input
          type="checkbox"
          class="form-check-input"
          id="removeSubPermissions"
          name="remove_sub_permissions"
          checked
        />
        <label class="form-check-label" for="removeSubPermissions" style="display: inline">
          <small>{% trans "Remove permissions in child projects" %}</small>
        </label>
      </div>
      {% endif %}
    </form>
    {% endif %}
  </td>
</tr>
